package Application.Window;

import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import Application.Application;
import Application.ServerHandler;
import Application.AppStates.AppStatesHandler;
import Application.Components.DiningList.DiningList;
import Application.Components.ImageShow.ImageShowManager;
import Application.Components.Schedule.Schedule;

public class Window extends Frame{
	private AppStatesHandler appStatesHandler;
	
	private Schedule schedule;
	private ImageShowManager imgShow;
	private DiningList diningList;
	
	private ServerHandler serverHandler;
	private Application application;
	
	private Toolkit toolkit;
	
	private int width, height;
	
	public Window(ServerHandler sh, Application app, AppStatesHandler ash, int width, int height, Schedule schedule, ImageShowManager ism, DiningList dl){
		super();
		
		this.appStatesHandler	= ash;
		this.serverHandler = sh;
		this.application = app;
		
		this.schedule		= schedule;
		this.imgShow		= ism;
		this.diningList		= dl;
		imgShow.nextImage();

		this.width	= width;
		this.height	= height;
		
		setUndecorated(true);
		setSize(width, height);
		setBackground(Color.BLACK);
		
		setVisible(true);
		onEvents();
	}
	
	private void onEvents(){
		addMouseMotionListener(new MouseMotionListener() {
			
			@Override
			public void mouseMoved(MouseEvent arg0) {
			/*	application.stop();
				serverHandler.stop();
				setVisible(false);
				System.exit(0);*/
			}
			
			@Override
			public void mouseDragged(MouseEvent arg0) {
				application.stop();
				serverHandler.stop();
				setVisible(false);
				System.exit(0);
			}
		}); 
	}
	
	public int getWidth(){
		return width;
	}
	
	public int getHeight(){
		return height;
	}
	
	@Override
	public void paint(Graphics g) {
		g.clearRect(0, 0, width, height);
		
		switch(appStatesHandler.getCurrentAppStates()){
			case diningList:				
				diningList.draw(g);
	
				break;
			case none:
				imgShow.nextImage();				
				imgShow.draw(g);
				
				break;
			case schedule:
				schedule.draw(g);
				break;
		}
		super.paint(g);
	}
}